<?php

/**
 * ecshop ERP v1.0
 * ----------------------------------------------------------------------------
 * http://www.phpally.com
 * Jacklee的博客 致力于php技术
 * ----------------------------------------------------------------------------
 * 作者: Jacklee
 * 邮箱: jack349392900@gmail.com
 * 创建时间: 2013-11-18
 * 最后修改时间: 2013-11-18
 */
 
 
define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');
require(dirname(__FILE__) . '/includes/lib/lib_erp_base.php');
require(dirname(__FILE__) . '/includes/lib/lib_erp_common.php');
require(dirname(__FILE__) . '/includes/lib/lib_erp_order.php');
require(dirname(__FILE__) . '/includes/lib/lib_erp_supplier.php');
require(dirname(__FILE__) . '/includes/lib/lib_erp_goods.php');
require(dirname(__FILE__) . '/includes/lib/lib_erp_goods_attr.php');


if ($_REQUEST['act'] == 'change_description')
{
	include('../includes/cls_json.php');
	$json  = new JSON;
	
	//检查是否有编辑订单的权限
	if(!admin_priv('erp_order_manage', '', false))
	{
		$result['error']=1;
		$result['message']=$_LANG['erp_no_permit'];
		die($json->encode($result));
	}
	
	$order_id=intval($_REQUEST['order_id']);
	$new_description=trim($_REQUEST['new_description']);

 	//判断订单是否存在，是否已被删除
	if(!is_order_exists($order_id))
	{
		$result['error']=4;
		$result['message']=$_LANG['erp_order_not_exist'];
		die($json->encode($result));
	}
	
	if(lock_order($order_id,'edit'))	
	{
			$result['error']=0;
			$sql="update ".$ecs->table('erp_order')." set description='".$new_description."' where order_id='".$order_id."'";
			$db->query($sql);

			die($json->encode($result));
	}
	else{
		$result['error']=-1;
		$result['message']=$_LANG['erp_order_no_accessibility'];
		die($json->encode($result));		
	}
}
elseif ($_REQUEST['act'] == 'change_supplier')
{
	include('../includes/cls_json.php');
	$json  = new JSON;
	
	//检查是否有编辑订单的权限
	if(!admin_priv('erp_order_manage', '', false))
	{
		$result['error']=1;
		$result['message']=$_LANG['erp_no_permit'];
		die($json->encode($result));
	}
	
	$order_id=intval($_REQUEST['order_id']);
	$supplier_code=trim($_REQUEST['supplier_code']);
	
 	//判断订单是否存在，是否已被删除
	if(!is_order_exists($order_id))
	{
		$result['error']=4;
		$result['message']=$_LANG['erp_order_not_exist'];
		die($json->encode($result));
	}
	
	if(lock_order($order_id,'edit'))	
	{
		if(is_supplier_exist('',$supplier_code))
		{			
				$sql="select supplier_id from ".$ecs->table('erp_supplier')." where code='".$supplier_code."'";
				$supplier_id=$db->getOne($sql);
				
				$sql="update ".$ecs->table('erp_order')." set supplier_id='".$supplier_id."' where order_id='".$order_id."'";
				$db->query($sql);
				
				delete_order_item($order_id);
				
				$result['error']=0;
				die($json->encode($result));
		}
		else{
			$result['error']=4;
			$result['message']=$_LANG['erp_order_supplier_not_exist'];
			die($json->encode($result));
		}
	}
	else{
		$result['error']=-1;
		$result['message']=$_LANG['erp_order_no_accessibility'];
		die($json->encode($result));		
	}
}

elseif ($_REQUEST['act'] == 'get_goods_attr')
{
	include('../includes/cls_json.php');
	$json  = new JSON;	
	
	//检查是否有编辑订单的权限
	if(!admin_priv('erp_order_manage', '', false))
	{
		$result['error']=1;
		$result['message']=$_LANG['erp_no_permit'];
		die($json->encode($result));
	}
	
	$order_id=intval($_REQUEST['order_id']);
	$order_item_id=intval($_REQUEST['order_item_id']);
	
	//判断订单项是否存在，是否已被删除
	if(!is_order_item_exists($order_item_id))
	{
		$result['error']=5;
		$result['message']=$_LANG['erp_order_item_not_exist'];
		die($json->encode($result));
	}	
	
	if(lock_order($order_id,'edit'))	
	{
		$sql="select goods_id from ".$GLOBALS['ecs']->table('erp_order_item')." where order_item_id='".$order_item_id."'";
		$goods_id=$GLOBALS['db']->getOne($sql);
		
		if(empty($goods_id))
		{
			$result['error']=5;
			$result['message']=$_LANG['erp_order_select_goods_in_advance'];
			die($json->encode($result));			
		}
		else{
			$goods_attr=get_goods_attr($goods_id);
			
			if(empty($goods_attr))
			{
				$result['error']=5;
				$result['message']=$_LANG['erp_order_goods_without_attr'];
				die($json->encode($result));					
			}
			else{
				$smarty->assign('goods_attr', $goods_attr);
				$attr_info=$smarty->fetch('erp_goods_attr.htm');
				
				$result['error']=0;
				$result['attr_info']=$attr_info;
				$result['attr_num']=count($goods_attr);

				die($json->encode($result));					
			}
		}
		
	}
	else{
		$result['error']=-1;
		$result['message']=$_LANG['erp_order_no_accessibility'];
		die($json->encode($result));		
	}		
}

/* 退回订单，重新编辑 */
elseif($_REQUEST['act'] == 'withdrawal_to_edit')
{
	include('../includes/cls_json.php');
	$json  = new JSON;	
	
	if(!admin_priv('erp_order_rate', '', false))
	{
		$result['error']=1;
		$result['message']=$_LANG['erp_no_permit'];
		die($json->encode($result));
	}
	
	$order_id=intval($_REQUEST['order_id']);
	
 	//判断订单是否存在，是否已被删除
	if(!is_order_exists($order_id))
	{
		$result['error']=4;
		$result['message']=$_LANG['erp_order_not_exist'];
		die($json->encode($result));
	}
	
	$sql="update ".$GLOBALS['ecs']->table('erp_order')."set order_status='1' where order_id='".$order_id."'";
	$GLOBALS['db']->query($sql);	
	
	$result['error']=0;
	die($json->encode($result));	
}


/* 退回订单，重新定价 */
elseif($_REQUEST['act'] == 'withdrawal_to_rate')
{
	include('../includes/cls_json.php');
	$json  = new JSON;	
	
	if(!admin_priv('erp_order_approve', '', false))
	{
		$result['error']=1;
		$result['message']=$_LANG['erp_no_permit'];
		die($json->encode($result));
	}
	
	$order_id=intval($_REQUEST['order_id']);
	
 	//判断订单是否存在，是否已被删除
	if(!is_order_exists($order_id))
	{
		$result['error']=4;
		$result['message']=$_LANG['erp_order_not_exist'];
		die($json->encode($result));
	}
	
	$sql="update ".$GLOBALS['ecs']->table('erp_order')."set order_status='2' where order_id='".$order_id."'";
	$GLOBALS['db']->query($sql);	
	
	$result['error']=0;
	die($json->encode($result));	
}

elseif ($_REQUEST['act'] == 'set_goods_attr')
{
	include('../includes/cls_json.php');
	$json  = new JSON;	
	
	//检查是否有编辑订单的权限
	if(!admin_priv('erp_order_manage', '', false))
	{
		$result['error']=1;
		$result['message']=$_LANG['erp_no_permit'];
		die($json->encode($result));
	}
	
	$order_id=intval($_REQUEST['order_id']);
	$order_item_id=intval($_REQUEST['order_item_id']);
	$ids=trim($_REQUEST['ids']);
	
	//判断订单项是否存在，是否已被删除
	if(!is_order_item_exists($order_item_id))
	{
		$result['error']=5;
		$result['message']=$_LANG['erp_order_item_not_exist'];
		die($json->encode($result));
	}
		
	if(lock_order($order_id,'edit'))	
	{
		$sql="select goods_id from ".$GLOBALS['ecs']->table('erp_order_item')." where order_item_id='".$order_item_id."'";
		$goods_id=$GLOBALS['db']->getOne($sql);
		
		$attr_id=get_attr_id($goods_id,$ids);
		
		$sql="update ".$GLOBALS['ecs']->table('erp_order_item')."set attr_id='".$attr_id."' where order_item_id='".$order_item_id."'";
		$GLOBALS['db']->query($sql);		
		
		//相同的属性，要合并
		$sql="select * from ".$GLOBALS['ecs']->table('erp_order_item')." where order_id='".$order_id."' and goods_id='".$goods_id."' and attr_id='".$attr_id."'";
		$order_item_info=$GLOBALS['db']->getAll($sql);
		if(!empty($order_item_info) && count($order_item_info)>=2)
		{
			$order_qty=0;
			foreach($order_item_info as $key => $order_item)
			{
				$order_qty+=$order_item['order_qty'];
			}
			
			$sql="update ".$GLOBALS['ecs']->table('erp_order_item')." set order_qty='".$order_qty."' where order_item_id='".$order_item_id."'";
			$GLOBALS['db']->query($sql);	
			
			$sql="delete from ".$GLOBALS['ecs']->table('erp_order_item')." where order_id='".$order_id."' and attr_id='".$attr_id."' and order_item_id<>'".$order_item_id."'";
			$GLOBALS['db']->query($sql);							
		}
		
		$result['error']=0;
		die($json->encode($result));				
	}
	else{
		$result['error']=-1;
		$result['message']=$_LANG['erp_order_no_accessibility'];
		die($json->encode($result));		
	}		
}



elseif ($_REQUEST['act'] == 'change_goods_sn')
{
	include('../includes/cls_json.php');
	$json  = new JSON;

	//检查是否有编辑订单的权限
	if(!admin_priv('erp_order_manage', '', false))
	{
		$result['error']=1;
		$result['message']=$_LANG['erp_no_permit'];
		die($json->encode($result));
	}

	$order_item_id=intval($_REQUEST['order_item_id']);
	$order_id=intval($_REQUEST['order_id']);
	$goods_sn=trim($_REQUEST['goods_sn']);
 	
	//判断订单项是否存在，是否已被删除
	if(!is_order_item_exists($order_item_id))
	{
		$result['error']=5;
		$result['message']=$_LANG['erp_order_item_not_exist'];
		die($json->encode($result));
	}
	
	//产品是否存在
	if(!is_goods_exist('',$goods_sn))
	{
		$result['error']=5;
		$result['message']=$_LANG['erp_order_goods_not_exist'];
		die($json->encode($result));			
	}
	
	//是否对产品有管理权
	//if(!is_admin_goods(erp_get_admin_id(),'',$goods_sn))
	//{
	//	$result['error']=5;
	//	$result['message']=$_LANG['erp_order_not_admin_goods'];
	//	die($json->encode($result));	
	//}
	
	$sql="select supplier_id from ".$GLOBALS['ecs']->table('erp_order')." where order_id='".$order_id."'";
	$supplier_id=$GLOBALS['db']->getOne($sql);
	//是否是供应商下的商品
	if(!is_supplier_goods($supplier_id,'',$goods_sn))
	{
		$result['error']=5;
		$result['message']=$_LANG['erp_order_not_supplier_goods'];
		die($json->encode($result));	
	}	
	
	if(lock_order($order_id,'edit'))	
	{

				//更新订单项				
				$sql="select goods_id from ".$GLOBALS['ecs']->table('goods')." where goods_sn='".$goods_sn."'";
				$goods_id=$GLOBALS['db']->getOne($sql);
				
				$sql="update ".$GLOBALS['ecs']->table('erp_order_item')." set goods_id='".$goods_id."' ";
				$sql.=", attr_id='0'" ;		
				$sql.=" where order_item_id='".$order_item_id."'";
				
				$GLOBALS['db']->query($sql);
					
				$result['error']=0;
				die($json->encode($result));
	}
	else{
		$result['error']=-1;
		$result['message']=$_LANG['erp_order_no_accessibility'];
		die($json->encode($result));		
	}	
	
}

elseif ($_REQUEST['act'] == 'delete_order')
{
	include('../includes/cls_json.php');
	$json  = new JSON;
	
	//检查是否有编辑订单的权限
	if(!admin_priv('erp_order_manage', '', false))
	{
		$result['error']=1;
		$result['message']=$_LANG['erp_no_permit'];
		die($json->encode($result));
	}

	$order_id=intval($_REQUEST['order_id']);
	
 	//判断订单是否存在，是否已被删除
	if(!is_order_exists($order_id))
	{
		$result['error']=4;
		$result['message']=$_LANG['erp_order_not_exist'];
		die($json->encode($result));
	}
	
	if(lock_order($order_id,'delete'))	
	{			
			//删除订单
			if(delete_order_item($order_id) && delete_order($order_id))
			{
				$result['error']=0;
				$result['message']=$_LANG['erp_order_delete_sucess'];
				die($json->encode($result));	
			}
	}
	else{
		$result['error']=-1;
		$result['message']=$_LANG['erp_order_no_accessibility'];
		die($json->encode($result));		
	}
}

elseif ($_REQUEST['act'] == 'post_to_rate')
{
	include('../includes/cls_json.php');
	$json  = new JSON;

	//检查是否有编辑订单的权限
	if(!admin_priv('erp_order_manage', '', false))
	{
		$result['error']=1;
		$result['message']=$_LANG['erp_no_permit'];
		die($json->encode($result));
	}
	
	$order_id=intval($_REQUEST['order_id']);
	
 	//判断订单是否存在，是否已被删除
	if(!is_order_exists($order_id))
	{
		$result['error']=4;
		$result['message']=$_LANG['erp_order_not_exist'];
		die($json->encode($result));
	}
	
	//检查该订单是否已完善
	$order_integrity=check_order_integrity($order_id);
	if($order_integrity!==true)
	{
			$result['error']=5;
			$result['message']=$_LANG['erp_order_not_completed'];
			die($json->encode($result));		
	}
		
	if(lock_order($order_id,'post_to_rate'))	
	{
		if(order_act_record($order_id,'post'))
		{		
			if(post_order($order_id))
			{
				$result['error']=0;
				$result['message']=$_LANG['erp_order_post_success'];
				die($json->encode($result));
			}
			else{
				$result['error']=3;
				$result['message']=$_LANG['erp_order_post_failed'];
				die($json->encode($result));				
			}
		}
	}
	else{
		$result['error']=-1;
		$result['message']=$_LANG['erp_order_no_accessibility'];
		die($json->encode($result));		
	}
	
}


elseif ($_REQUEST['act'] == 'change_order_qty')
{
	include('../includes/cls_json.php');
	$json  = new JSON;

	//检查是否有编辑订单的权限
	if(!admin_priv('erp_order_manage', '', false))
	{
		$result['error']=1;
		$result['message']=$_LANG['erp_no_permit'];
		die($json->encode($result));
	}
	
	$order_id=intval($_REQUEST['order_id']);
	$order_item_id=intval($_REQUEST['order_item_id']);
	$order_qty=intval($_REQUEST['order_qty']);
 	
	if(!is_order_item_exists($order_item_id))
	{
		$result['error']=4;
		$result['message']=$_LANG['erp_order_item_not_exist'];
		die($json->encode($result));
	}		

	if(lock_order($order_id,'edit'))	
	{
			$sql="update ".$GLOBALS['ecs']->table('erp_order_item')." set order_qty='".$order_qty."' where order_item_id='".$order_item_id."'";
			$GLOBALS['db']->query($sql);		

			$result['error']=0;
			$result['message']='';
			die($json->encode($result));

	}
	else{
		$result['error']=-1;
		$result['message']=$_LANG['erp_order_no_accessibility'];
		die($json->encode($result));		
	}		
}

elseif ($_REQUEST['act'] == 'delete_order_item')
{
	include('../includes/cls_json.php');
	$json  = new JSON;

	//检查是否有编辑订单的权限
	if(!admin_priv('erp_order_manage', '', false))
	{
		$result['error']=1;
		$result['message']=$_LANG['erp_no_permit'];
		die($json->encode($result));
	}
	
	$order_id=intval($_REQUEST['order_id']);
	$order_item_id=intval($_REQUEST['order_item_id']);

 	
	//判断订单项是否存在，是否已被删除
	if(!is_order_item_exists($order_item_id))
	{
		$result['error']=5;
		$result['message']=$_LANG['erp_order_item_not_exist'];
		die($json->encode($result));
	}

	if(lock_order($order_id,'delete'))	
	{
	
			delete_order_item('',$order_item_id);
					
			$result['error']=0;
			die($json->encode($result));

	}
	else{
		$result['error']=-1;
		$result['message']=$_LANG['erp_order_no_accessibility'];
		die($json->encode($result));		
	}		
}

elseif ($_REQUEST['act'] == 'add_order_item')
{
	include('../includes/cls_json.php');
	$json  = new JSON;

	//检查是否有编辑订单的权限
	if(!admin_priv('erp_order_manage', '', false))
	{
		$result['error']=1;
		$result['message']=$_LANG['erp_no_permit'];
		die($json->encode($result));
	}
	
	$order_id=intval($_REQUEST['order_id']);

 	//判断订单是否存在，是否已被删除
	if(!is_order_exists($order_id))
	{
		$result['error']=4;
		$result['message']=$_LANG['erp_order_not_exist'];
		die($json->encode($result));
	}	
 	
	if(lock_order($order_id,'edit'))	
	{
			$sql="insert into ".$GLOBALS['ecs']->table('erp_order_item')." set order_id='".$order_id."'";
			$GLOBALS['db']->query($sql);
			
			$result['error']=0;
			die($json->encode($result));
		
	}
	else{
		$result['error']=-1;
		$result['message']=$_LANG['erp_order_no_accessibility'];
		die($json->encode($result));		
	}		
}



elseif ($_REQUEST['act'] == 'change_specs')
{
	include('../includes/cls_json.php');
	$json  = new JSON;

	//检查是否有编辑订单的权限
	if(!admin_priv('erp_order_manage', '', false))
	{
		$result['error']=1;
		$result['message']=$_LANG['erp_no_permit'];
		die($json->encode($result));
	}

	$order_id=intval($_REQUEST['order_id']);
	$order_item_id=intval($_REQUEST['order_item_id']);
	$specific_desc=trim($_REQUEST['specific_desc']);

 	//判断订单是否存在，是否已被删除
	if(!is_order_item_exists($order_item_id))
	{
		$result['error']=4;
		$result['message']=$_LANG['erp_order_item_not_exist'];
		die($json->encode($result));
	}	
 	
	if(lock_order($order_id,'edit'))	
	{
				$sql="update ".$GLOBALS['ecs']->table('erp_order_item')." set ";

				$sql.="specific_desc='".$specific_desc."'";

				$sql.="where order_item_id='".$order_item_id."'";	
	
				if($GLOBALS['db']->query($sql))
				{
					$result['error']=0;
					
					die($json->encode($result));					
				}
	}
	else{
		$result['error']=-1;
		$result['message']=$_LANG['erp_order_no_accessibility'];
		die($json->encode($result));		
	}		
}


elseif ($_REQUEST['act'] == 'change_price')
{
	include('../includes/cls_json.php');
	$json  = new JSON;

	//检查是否有编辑订单价格的权限
	if(!admin_priv('erp_order_rate', '', false))
	{
		$result['error']=1;
		$result['message']=$_LANG['erp_no_permit'];
		die($json->encode($result));
	}

	$order_id=intval($_REQUEST['order_id']);
	$order_item_id=intval($_REQUEST['order_item_id']);
	
	$price=$_REQUEST['price'];
	
 	//判断订单是否存在，是否已被删除
	if(!is_order_item_exists($order_item_id))
	{
		$result['error']=4;
		$result['message']=$_LANG['erp_order_item_not_exist'];
		die($json->encode($result));
	}		
 	
	if(lock_order($order_id,'rate'))	
	{
		if(order_act_record($order_id,'rate'))
		{	
				$sql="update ".$GLOBALS['ecs']->table('erp_order_item')." set price='".$price."',amount=order_qty*price where order_item_id=".$order_item_id."";
				$GLOBALS['db']->query($sql);
				
				$result['error']=0;
				die($json->encode($result));				
		}
	}
	else{
		$result['error']=-1;
		$result['message']=$_LANG['erp_order_no_accessibility'];
		die($json->encode($result));		
	}		
}


elseif ($_REQUEST['act'] == 'post_to_approve')
{
	include('../includes/cls_json.php');
	$json  = new JSON;

	//检查是否有编辑订单价格的权限
	if(!admin_priv('erp_order_rate', '', false))
	{
		$result['error']=1;
		$result['message']=$_LANG['erp_no_permit'];
		die($json->encode($result));
	}

	$order_id=intval($_REQUEST['order_id']);
	
 	//判断订单是否存在，是否已被删除
	if(!is_order_exists($order_id))
	{
		$result['error']=4;
		$result['message']=$_LANG['erp_order_not_exist'];
		die($json->encode($result));
	}	
 
	if(lock_order($order_id,'post_to_approve'))	
	{
		if(order_act_record($order_id,'submit'))
		{	
			$sql="update ".$GLOBALS['ecs']->table('erp_order')." set ";
			$sql.="order_status ='3' ";
			$sql.="where order_id='".$order_id."'";	
			
			if($GLOBALS['db']->query($sql))
			{
				$result['error']=0;
				$result['message']=$_LANG['erp_order_post_success'];
				
				die($json->encode($result));		
			}
		}
	}
	else{
		$result['error']=-1;
		$result['message']=$_LANG['erp_order_no_accessibility'];
		die($json->encode($result));		
	}	
		
}


elseif ($_REQUEST['act'] == 'approve_pass' || $_REQUEST['act'] == 'approve_reject')
{
	include('../includes/cls_json.php');
	$json  = new JSON;

	//检查是否有审核订单的权限
	if(!admin_priv('erp_order_approve', '', false))
	{
		$result['error']=1;
		$result['message']=$_LANG['erp_no_permit'];
		die($json->encode($result));
	}

	$order_id=intval($_REQUEST['order_id']);
	$approve_remark=trim($_REQUEST['approve_remark']);
	$act=$_REQUEST['act'];
	
 	//判断订单是否存在，是否已被删除
	if(!is_order_exists($order_id))
	{
		$result['error']=4;
		$result['message']=$_LANG['erp_order_not_exist'];
		die($json->encode($result));
	}	
 
	if(lock_order($order_id,'approve'))	
	{
		if(order_act_record($order_id,'approve'))
		{	
			if($act=='approve_pass')
			{
				$sql="update ".$GLOBALS['ecs']->table('erp_order')." set ";
				$sql.="order_status ='4', approve_remark='".$approve_remark."' ";
				$sql.="where order_id='".$order_id."'";					
			}
			else if($act=='approve_reject')
			{
				$sql="update ".$GLOBALS['ecs']->table('erp_order')." set ";
				$sql.="order_status ='5', approve_remark='".$approve_remark."' ";
				$sql.="where order_id='".$order_id."'";					
			}
			
			if($GLOBALS['db']->query($sql))
			{
				$result['error']=0;
				$result['message']=$_LANG['erp_order_approve_success'];
				
				die($json->encode($result));		
			}
		}
	}
	else{
		$result['error']=-1;
		$result['message']=$_LANG['erp_order_no_accessibility'];
		die($json->encode($result));		
	}	
}

/* 退回订单，重新定价 */
elseif($_REQUEST['act'] == 'execute_order')
{
	include('../includes/cls_json.php');
	$json  = new JSON;	
	
	if(!admin_priv('erp_order_execute', '', false))
	{
		$result['error']=1;
		$result['message']=$_LANG['erp_no_permit'];
		die($json->encode($result));
	}
	
	$order_id=intval($_REQUEST['order_id']);
	
 	//判断订单是否存在，是否已被删除
	if(!is_order_exists($order_id))
	{
		$result['error']=4;
		$result['message']=$_LANG['erp_order_not_exist'];
		die($json->encode($result));
	}
	
	$sql="update ".$GLOBALS['ecs']->table('erp_order')."set order_status='6',execute_time='".time()."',execute_by='".erp_get_admin_id()."' where order_id='".$order_id."'";
	$GLOBALS['db']->query($sql);	
	
	$result['error']=0;
	die($json->encode($result));	
}

/* 退回订单，重新定价 */
elseif($_REQUEST['act'] == 'finish_order')
{
	include('../includes/cls_json.php');
	$json  = new JSON;	
	
	if(!admin_priv('erp_order_finish', '', false))
	{
		$result['error']=1;
		$result['message']=$_LANG['erp_no_permit'];
		die($json->encode($result));
	}
	
	$order_id=intval($_REQUEST['order_id']);
	
 	//判断订单是否存在，是否已被删除
	if(!is_order_exists($order_id))
	{
		$result['error']=4;
		$result['message']=$_LANG['erp_order_not_exist'];
		die($json->encode($result));
	}
	
	$sql="update ".$GLOBALS['ecs']->table('erp_order')."set order_status='7',finish_time='".time()."',finish_by='".erp_get_admin_id()."' where order_id='".$order_id."'";
	$GLOBALS['db']->query($sql);	
	
	$result['error']=0;
	die($json->encode($result));	
}


?>